package com.erp.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;

import com.erp.dto.Article;
import com.erp.dto.User;
import com.erp.mapping.ArticleType;
import com.erp.mapping.Status;

@MappedSuperclass
public class TArticle {

	protected Integer id;
	protected String content;// 内容

	protected TUser author;// 作者
	protected Date postTime;// 发表时间
	protected String ipAddr;// 发表文章时所用的IP地址
	protected ArticleType articleType = ArticleType.TYPE_COMMON;// 文章类型，默认一般类型
	protected Status status = Status.STATUS_NORMAL;// 文章状态，默认正常状态

	public TArticle() {

	}

	public TArticle(Article article) {
		this.id = article.getId();
		this.content = article.getContent();
		User user = article.getAuthor();
		if (user != null) {
			this.author = new TUser(user);
		}
		this.postTime = article.getPostTime();
		this.ipAddr = article.getIpAddr();
		this.articleType = article.getArticleType();
		this.status = article.getStatus();
	}

	@Id
	@GeneratedValue
	@Column(name = "id")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "content")
	@Lob
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	/**
	 * 本类与TUser是多对一单向关系
	 * 
	 * @return
	 */
	@ManyToOne
	@JoinColumn(name = "author_id")
	public TUser getAuthor() {
		return author;
	}

	public void setAuthor(TUser author) {
		this.author = author;
	}

	@Column(name = "postTime")
	public Date getPostTime() {
		return postTime;
	}

	public void setPostTime(Date postTime) {
		this.postTime = postTime;
	}

	@Column(name = "ipAddr")
	public String getIpAddr() {
		return ipAddr;
	}

	public void setIpAddr(String ipAddr) {
		this.ipAddr = ipAddr;
	}

	@Enumerated(EnumType.ORDINAL)
	@Column(name = "type")
	public ArticleType getArticleType() {
		return articleType;
	}

	public void setArticleType(ArticleType articleType) {
		this.articleType = articleType;
	}

	@Enumerated(EnumType.ORDINAL)
	@Column(name = "status")
	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

}
